import { ref, type Ref } from "vue"
import http, { delHttp } from "../utils/http"
import { useSave } from "@/store"


// 检查用户是否已注册
export const checkUserExists = (phoneNum: string) => {
  return http.get('/classes/Users', {
    params: { where: JSON.stringify({ phone: phoneNum }) }
  })
}

// 注册接口
export const userRegister = (phoneNum:string,avatar:string,username:string,password:string)=>{
	return http.post('/classes/Users',{
		phone:phoneNum,
		avatar,
		username,
		password
	})
}




export interface userputType {
	avatar?:string,
	username?:string,
	password?:string
}
//判断应该修改的是哪一条user数据
const checkStore = useSave()
let ID:Ref<string | undefined> = ref(checkStore.userInfo?.objectId)

//更新接口
export const userUpdate = (date:userputType)=>{
	return http.put(`/classes/Users/${ID.value}`,date)
}

//获取单条数据接口
export const userGet = (id:string)=>{
	return delHttp.get(`/classes/Users/${id}`)
}

//删除接口
export const userDelete = ()=>{
	return delHttp.delete(`/classes/Users/${ID.value}`)
}